<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:fn="http://java.sun.com/jsp/jstl/functions"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	template="/WEB-INF/templates/template.xhtml">
			
	<ui:define name="breadcrumb">
		<ui:include src="breadcrumb.xhtml" />
	</ui:define>
	<ui:define name="menu">
		<ui:include src="/admin/menu.xhtml" />
	</ui:define>
	<ui:define name="title">#{messages.groupsConsultaHeader}</ui:define>
	<ui:define name="content">
		<h:form id="form">
			<rich:messages for="gv" 
				infoClass="green" 
				errorClass="red" 
				globalOnly="true" 
				ajaxRendered="true" />
			<div id="form_box">
				<div id="form_left">
					<h:panelGrid columns="2">
						<h:outputLabel styleClass="tarragona-search-label" 
							value="#{messages.groupsSearchNombre}:"/>
						<h:inputText id="buscarNombre" 
							value="#{groupBean.input.text}">
						</h:inputText>
					</h:panelGrid>
				</div>	
				<div class="clearer"></div>
				
			</div>
			<div id="butons">
				<h:panelGrid columns="2" width="100%" columnClasses="buttons-search,buttons-create">
					<h:commandButton value="#{messages.search}" 
						action="#{groupBean.search}" />
	
					<h:commandButton value="#{messages.groupsCreate}" 
						action="#{createGroupBean.showCreate}">
						<f:setPropertyActionListener value="#{facesContext.viewRoot.viewId}" 
							target="#{createUserBean.persistReturnView}" />
					</h:commandButton>									
				</h:panelGrid>
				<h:panelGrid columns="1"/>
				<rich:dataTable value="#{groupBean.dataModel}"
					iterationStatusVar="it" id="resultTable" var="result" rows="10"
					rendered="#{groupBean.searchActive}">
 
	     			<rich:column>
	      				<f:facet name="header"></f:facet>
	      				<h:selectBooleanCheckbox value="#{result.selected}" />
	      			</rich:column>
	      			
        			<rich:column>
        				<f:facet name="header">
        					<h:outputText value="#{messages.groupsUsername}"/>
        				</f:facet>
			        	<h:commandLink action="#{editUserBean.showEdit}" 
			        		value="#{result.entity.name}">
        					<f:setPropertyActionListener value="#{result.entity}" 
        						target="#{editUserBean.user}" />
							<f:setPropertyActionListener value="#{facesContext.viewRoot.viewId}" 
								target="#{editUserBean.persistReturnView}" />        					
        				</h:commandLink>			        
        			</rich:column>

        			<rich:column>
        				<f:facet name="header">
        					<h:outputText value="#{messages.groupsRoles}"/>
        				</f:facet>
        				<h:outputText value="#{result.entity.groupAuthorities}" />
        			</rich:column>

        			<rich:column>
        				<f:facet name="header">
        					<h:outputText value="#{messages.groupsUsers}"/>
        				</f:facet>
        				<h:outputText value="#{result.entity.users}" />
        			</rich:column>

					<rich:column>
			        	<h:commandLink action="#{editUserBean.showEdit}">
        					<h:graphicImage value="/resources/icons/edit.gif" alt="edit"/>
        					<f:setPropertyActionListener value="#{result.entity}" target="#{editUserBean.user}" />
							<f:setPropertyActionListener value="#{facesContext.viewRoot.viewId}" 
								target="#{editUserBean.persistReturnView}" />        					
        				</h:commandLink>			        
			        
						<a4j:commandLink styleClass="no-decor" execute="@this"
							render="@none" oncomplete="#{rich:component('confirmPane')}.show()">
							<h:graphicImage value="/resources/icons/delete.gif" alt="delete" />
        					<f:setPropertyActionListener value="#{result.entity}" target="#{groupBean.entity}" />
						</a4j:commandLink>						
					</rich:column>
				</rich:dataTable>
				
				<h:panelGrid rendered="#{groupBean.searchActive}" 
					columns="2" width="100%" columnClasses="buttons-search,buttons-create">
					<h:commandButton value="#{messages.exportToExcel}" 
						action="#{groupBean.exportToExcel}"/>
				</h:panelGrid>
			</div>	
		</h:form>	
	</ui:define>	
</ui:composition>